﻿using PTTK_HTTT_06.BUS;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace PTTK_HTTT_06.DAO
{
    class DON_DAT_HANG_DB
    {
        public static void ThemDonDatHang(DON_DAT_HANG _nguyenLieu)
        {
            DataProvider _provider = new DataProvider();
            _provider.Connect();
            SqlParameter[] _para =
            {
                new SqlParameter("@MaNhanVien",SqlDbType.Int){Value = _nguyenLieu.MaNhanVien.ToString()},
                new SqlParameter("@NgayLap",SqlDbType.DateTime){Value = _nguyenLieu.NgayLap},
                new SqlParameter("@NgayGiao",SqlDbType.DateTime){Value = _nguyenLieu.NgayGiao},
                new SqlParameter("@TongTien",SqlDbType.Money){Value = _nguyenLieu.TongTien},
                new SqlParameter("@TinhTrang",SqlDbType.Int){Value = _nguyenLieu.TinhTrang}                
            };
            _provider.ExcuteProcedure("usp_ThemDonDatHang", _para);
            _provider.Disconnect();
        }

        internal static int LayMaDonDatHang()
        {
            DataProvider _provider = new DataProvider();
            _provider.Connect();
            string sql = "select top 1 MaDonDatHang from DON_DAT_HANG order by MaDonDatHang DESC";
            DataTable dt = _provider.ExcuteQueryDataTable(sql);
            _provider.Disconnect();
            return int.Parse(dt.Rows[0][0].ToString());
        }
    }
}
